package practice;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class ArrayCollectionCast {
    public static void main(String[] args) {
        //第一遍
        //集合转化为数组
        Collection<String> c1 = new ArrayList();
        c1.add("abc");
        c1.add("java");
        c1.add("###");
        c1.add("!!!");

        String[] c2 = c1.toArray(new String[0]);
        System.out.println(Arrays.toString(c2));

        //数组转化为集合
        String[] c3 = {"123","abc","999","qqq"};
        List c4 = Arrays.asList(c3);
        System.out.println(c4);

        c3[1] = "???";
        System.out.println(Arrays.toString(c3));
        System.out.println(c4);

        c4.set(2,"777");
        System.out.println(Arrays.toString(c3));
        System.out.println(c4);

        //第二遍
        //集合转化为数组
        Collection<String> a1 = new ArrayList();
        a1.add("123");
        a1.add("ccc");
        a1.add("TTT");
        a1.add("999");

        String[] a2 = a1.toArray(new String[0]);
        System.out.println(Arrays.toString(a2));

        //数组转化为集合
        String[] a3 = {"999","777","888"};
        List a4 = Arrays.asList(a3);
        System.out.println(a4);

        a3[1] = "lll";
        System.out.println(Arrays.toString(a3));
        System.out.println(a4);

        a4.set(2,"kkk");
        System.out.println(Arrays.toString(a3));
        System.out.println(a4);

    }
}
